﻿using BLL;
using IFactory;
using IFactory;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;



public partial class UserPlanWeek_UserPlanWeekListDisPlay : System.Web.UI.Page
{
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    IBussinessLogic dllMonthPlan = new MonthPlanManager();
    WeekDateManager dllWeekDateManager = new WeekDateManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
    Authentication dllAuthentication = new Authentication();
    Week_RemindofManager dllWeek_RemindofManager = new Week_RemindofManager();
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new System.Data.DataTable();
    public string PreWeekRemind = "";
    public string TheWeekRemind = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        //判断是否为经理，非经理锁定部门选择框
        this.drpDepartment.Enabled = false;
        DataTable dt = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["IsDepartmentManager"].ToString() != "1")
            {
                this.btnDel.Visible = false;
                this.btnModifyContinue.Visible = false;
                this.btnModifyMonth.Visible = false;
                this.btnModifyPre.Visible = false;
            }
        }
        if (objUserInfo.UserName == "admin")
        {
            this.drpDepartment.Enabled = true;
        }
        if (!IsPostBack)
        {
            //绑定
            bindDropDownList(this.drpDepartment);
            bindDropDownList(this.drpUserInfo);
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpQuarterDate);
            bindDropDownList(this.drpMonthDate);
            bindDropDownList(this.drpWeekDate);

            bindGridView(this.gdvWeekPlan);
            bindGridView(this.gdvPreWeekPlan);
            bindGridView(this.gdvPreWeekPlanNoCompelete);
            bindGridView(this.gdvWeekPlanContinue);
        }
        processGridViewForWeek(gdvWeekPlan);
        processGridViewPre(gdvPreWeekPlan);
        processGridView(gdvPreWeekPlanNoCompelete);
        processGridViewForWeek(gdvWeekPlanContinue);
    }

    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {
        //部门绑定
        if (_drp.Equals(this.drpDepartment))
        {
            this.drpDepartment.DataSource = dllDepartment.getNoTree();
            this.drpDepartment.DataTextField = "DepartmentName";
            this.drpDepartment.DataValueField = "DepartmentId";
            this.drpDepartment.DataBind();
            ListItem _li = new ListItem("请选择部门");
            this.drpDepartment.Items.Insert(0, _li);
            object[] _value = new object[1];
            _value[0] = objUserInfo.UserName;
            DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
            if (_userTable.Rows.Count > 0)
            {
                if (Request.Params["depart"] != null && Request.Params["depart"].ToString().Length != 0)
                {
                    this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByValue(Request.Params["depart"].ToString()));
                }
                else
                {
                    this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByText(_userTable.Rows[0]["DepartmentId"].ToString()));
                }
            }
        }
        //绑定用户
        if (_drp.Equals(this.drpUserInfo))
        {
            this.drpUserInfo.Items.Clear();
            object[] _value = new object[1];
            _value[0] = this.drpDepartment.SelectedItem.Text;
            DataTable _userInfo = dllUserInfoManager.getUserInfoByDepartmentName(_value);
            if (_userInfo.Rows.Count > 0)
            {
                this.drpUserInfo.DataSource = _userInfo;
                this.drpUserInfo.DataTextField = "RealName";
                this.drpUserInfo.DataValueField = "UserId";
                this.drpUserInfo.DataBind();
                ListItem _selectLi = new ListItem("请选择员工", "0");
                this.drpUserInfo.Items.Insert(0, _selectLi);
                object[] _valueuser = new object[1];
                _valueuser[0] = objUserInfo.UserName;
                DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _valueuser);
                if (_userTable.Rows.Count > 0)
                {
                    if (Request.Params["User"] != null && Request.Params["User"].ToString().Length != 0)
                    {
                        this.drpUserInfo.SelectedIndex = this.drpUserInfo.Items.IndexOf(this.drpUserInfo.Items.FindByValue(Request.Params["User"].ToString()));
                    }
                    else
                    {
                        this.drpUserInfo.SelectedIndex = this.drpUserInfo.Items.IndexOf(this.drpUserInfo.Items.FindByText(_userTable.Rows[0]["RealName"].ToString()));
                    }
                }
            }
            else
            {
                this.drpUserInfo.Items.Clear();
                ListItem _li = new ListItem("该部门无员工", "0");
                this.drpUserInfo.Items.Add(_li);
            }
        }
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
            if (Request.Params["Year"] != null && Request.Params["Year"].ToString().Length != 0)
            {

                this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(Request.Params["Year"].ToString()));

            }

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                if (Request.QueryString["QuarterDate"] == null)
                {
                    #region dropdownlist显示系统所对应的当前年周期
                    //根据系统当前日期查找到对应的年周期
                    DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                    //如果查到结果（结果只有一条）

                    if (_quartertime.Rows.Count > 0)
                    {
                        this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                        if (Request.Params["Quarter"] != null && Request.Params["Quarter"].ToString().Length != 0)
                        {

                            this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByValue(Request.Params["Quarter"].ToString()));

                        }

                    }
                    #endregion
                }
                else
                {
                    this.drpQuarterDate.SelectedValue = Utility.HttpHelp.getParamsString("QuarterDate");
                }
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期", "0");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }

        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                if (Request.QueryString["MonthDate"] == null)
                {
                    #region 根据系统当前日期绑定到当前月周期
                    DataTable _monthtime = dllMonthDateManager.getMonthDate();
                    if (_monthtime.Rows.Count > 0)
                    {
                        this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                        if (Request.Params["Month"] != null && Request.Params["Month"].ToString().Length != 0)
                        {

                            this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByValue(Request.Params["Month"].ToString()));

                        }

                    }
                    #endregion
                }
                else
                {
                    this.drpMonthDate.SelectedValue = Utility.HttpHelp.getParamsString("MonthDate");
                }
                bindDropDownList(this.drpWeekDate);
            }
            else
            {
                ListItem _li = new ListItem("无月周期", "0");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindDropDownList(this.drpWeekDate);
            }

        }
        //绑定周计划周期
        if (_drp.Equals(this.drpWeekDate))
        {
            object[] _value = new object[3];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            _value[2] = this.drpMonthDate.SelectedItem.Text;
            DataTable _week = dllWeekDateManager.get(WeekDateManager.field.MonthName.ToString(), _value);
            if (_week.Rows.Count != 0)
            {
                this.drpWeekDate.DataSource = _week;
                this.drpWeekDate.DataTextField = "WeekName";
                this.drpWeekDate.DataValueField = "Week_Id";
                this.drpWeekDate.DataBind();
                if (Request.QueryString["WeekDate"] == null)
                {
                    DataTable _weektime = dllWeekDateManager.getWeekDate();
                    if (_weektime.Rows.Count == 1)
                    {
                        this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByText(_weektime.Rows[0][4].ToString()));


                    }
                }
                else
                {
                    this.drpWeekDate.SelectedValue = Utility.HttpHelp.getParamsString("WeekDate");
                }
                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);

            }
            else
            {
                ListItem _li = new ListItem("无周周期", "0");
                this.drpWeekDate.Items.Clear();
                this.drpWeekDate.Items.Add(_li);
                bindGridView(this.gdvWeekPlan);
                bindGridView(this.gdvPreWeekPlan);
                bindGridView(this.gdvPreWeekPlanNoCompelete);
                bindGridView(this.gdvWeekPlanContinue);

            }
        }

    }




    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }


    //构建上周计划表结构并添加1行
    DataTable createDataTable()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("WeekPlanSortId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WorkItem");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Source");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CompleteTime");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MasterPeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartment");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartmentDuty");
        _dt.Columns.Add(dc);
        dc = new DataColumn("EvaluatePeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanSendState");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CheckNote");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Remart");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MonthPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("AttachmentPath");
        _dt.Columns.Add(dc);
        dc = new DataColumn("NoCompleteCount");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WeekPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanStep");
        _dt.Columns.Add(dc);
        dc = new DataColumn("VerifyPeopleOpinion");
        _dt.Columns.Add(dc);
        dc = new DataColumn("DepartWeekPlanId");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["WeekPlanSortId"] = "";
        dr["WorkItem"] = "";
        dr["Source"] = "";
        dr["CompleteTime"] = "";
        dr["MasterPeople"] = "";
        dr["SlaveDepartment"] = "";
        dr["SlaveDepartmentDuty"] = "";
        dr["EvaluatePeople"] = "";
        dr["PlanSendState"] = "0";
        dr["CheckNote"] = "";
        dr["Remart"] = "";
        dr["MonthPlanId"] = "";
        dr["NoCompleteCount"] = "";
        dr["AttachmentPath"] = "";
        dr["WeekPlanId"] = "";
        dr["PlanStep"] = "";
        dr["VerifyPeopleOpinion"] = "";
        dr["DepartWeekPlanId"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    //构建上周总结
    DataTable createWeekSummary()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("PreWeekSummary");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WeekSummary");
        _dt.Columns.Add(dc);
        dc = new DataColumn("AttachmentPath");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Id");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["PreWeekSummary"] = "";
        dr["WeekSummary"] = "";
        dr["AttachmentPath"] = "";
        dr["Id"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    /// <summary>
    /// 绑定gridview
    /// </summary>
    void bindGridView(GridView _gridView)
    {
        if (_gridView.Equals(this.gdvPreWeekPlan))
        {
            #region 绑定上周计划
            this.gdvPreWeekPlan.DataSource = new DataTable();
            this.gdvPreWeekPlan.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllUserPlanWeek.getPreUserWeekPlan(_value);
            if (_weekPlan.Tables.Count > 0)
            {
                for (int j = 0; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvPreWeekPlan.DataSource = dv;
                        this.gdvPreWeekPlan.DataBind();
                    }
                }
            }
            if (this.gdvPreWeekPlan.Rows.Count == 0)
            {
                this.gdvPreWeekPlan.DataSource = createDataTable();
                this.gdvPreWeekPlan.DataBind();
            }


            #region
            for (int i = 0; i < this.gdvPreWeekPlan.Rows.Count; i++)
            {

                if (this.gdvPreWeekPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)this.gdvPreWeekPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                    _btn.Visible = false;
                    Label _lbl = (Label)this.gdvPreWeekPlan.Rows[i].Cells[12].FindControl("lblAlert");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }
            #endregion

            #endregion
            processGridViewPre(_gridView);
        }
        if (_gridView.Equals(this.gdvPreWeekPlan))
        {
            object[] _valueSummary = new object[3];
            _valueSummary[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _valueSummary[1] = this.drpDepartment.SelectedItem.Text;
            _valueSummary[2] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
            DataTable dt = new BLL.UserWeekSummary().get(BLL.UserWeekSummary.field.WeekDate.ToString(), BLL.UserWeekSummary.field.Department.ToString(), _valueSummary);
            if (dt.Rows.Count > 0)
            {
                this.txtWeekSummary.Text = dt.Rows[0]["WeekSummary"].ToString();
                this.txtPreWeekSummary.Text = dt.Rows[0]["PreWeekSummary"].ToString();
                this.prelength.InnerHtml = this.txtPreWeekSummary.Text.Length.ToString();
                this.thelength.InnerHtml = this.txtWeekSummary.Text.Length.ToString();
                this.HWeekSummaryId.Value = dt.Rows[0]["Id"].ToString();
                this.HPreAttachmentPath.Value = dt.Rows[0]["PreAttachmentPath"].ToString();
                this.HAttachmentPath.Value = dt.Rows[0]["AttachmentPath"].ToString();
            }
            else
            {
                this.txtWeekSummary.Text = "注：工作部署不少于3条，总字数不少于60个字。";
                this.txtPreWeekSummary.Text = "注：工作总结不少于3条，总字数不少于60个字。";
                this.prelength.InnerHtml = "0";
                this.thelength.InnerHtml = "0";
                this.HWeekSummaryId.Value = string.Empty;
                this.HPreAttachmentPath.Value = string.Empty;
                this.HAttachmentPath.Value = string.Empty;
            }
            if (this.txtWeekSummary.Text.Length > 0 && this.txtWeekSummary.Text != "注：工作部署不少于3条，总字数不少于60个字。")
            {
                this.btnAddWeekSummary.Text = "修改";
            }
            else
            {
                this.btnAddWeekSummary.Text = "添加";
            }
            if (this.txtPreWeekSummary.Text.Length > 0 && this.txtPreWeekSummary.Text != "注：工作总结不少于3条，总字数不少于60个字。")
            {
                this.btnAddPreWeekSummary.Text = "修改";
            }
            else
            {
                this.btnAddPreWeekSummary.Text = "添加";
            }
            if (this.HPreAttachmentPath.Value.Length > 0)
            {
                this.btnDownPreWeek.Enabled = true;
            }
            else
            {
                this.btnDownPreWeek.Enabled = false;
            }
            if (this.HAttachmentPath.Value.Length > 0)
            {
                this.btnDownWeekSummary.Enabled = true;
            }
            else
            {
                this.btnDownWeekSummary.Enabled = false;
            }
            if (objUserInfo.UserName != "admin")
            {
                bool Isdepartment = false;
                //当前部门并且当前月份
                object[] _value = new object[1];
                _value[0] = objUserInfo.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
                if (_userTable.Rows.Count > 0)
                {
                    if (_userTable.Rows[0]["DepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text || _userTable.Rows[0]["PartTimeDepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text)
                    {
                        Isdepartment = true;
                    }
                }

                bool IsDate = new BLL.WeekDateManager().IsEditWeekSummary(new object[] { Convert.ToInt32(this.drpWeekDate.SelectedValue) });
                //DataTable _weektime = dllWeekDateManager.getWeekDate();
                //if (this.drpWeekDate.SelectedItem.Text == _weektime.Rows[0][4].ToString())
                //{
                //    IsDate = true;

                //}
                if (Isdepartment && IsDate && this.drpUserInfo.SelectedValue == _userTable.Rows[0]["UserId"].ToString())
                {
                    this.btnAddPreWeekSummary.Enabled = true;
                    this.btnAddWeekSummary.Enabled = true;
                    this.btnUploadPreWeekSummary.Enabled = true;
                    this.btnUploadWeekSummary.Enabled = true;
                }
                else
                {
                    this.btnAddPreWeekSummary.Enabled = false;
                    this.btnAddWeekSummary.Enabled = false;
                    this.btnUploadPreWeekSummary.Enabled = false;
                    this.btnUploadWeekSummary.Enabled = false;
                }
                this.btnSaveWeekSummary.Visible = false;
                this.btnSavePreWeekSummary.Visible = false;
                this.btnAddWeekSummary.Visible = true;
                this.btnAddPreWeekSummary.Visible = true;
            }
            this.txtPreWeekSummary.ReadOnly = true;
            this.txtWeekSummary.ReadOnly = true;
        }
        if (_gridView.Equals(this.gdvWeekPlan))
        {
            #region 绑定本周计划
            this.gdvWeekPlan.DataSource = new DataTable();
            this.gdvWeekPlan.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = this.dllUserPlanWeek.getUserWeekPlan(_value);
            if (_weekPlan.Tables.Count > 0)
            {
                for (int j = 0; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvWeekPlan.DataSource = dv;
                        this.gdvWeekPlan.DataBind();
                    }
                }
            }

            if (this.gdvWeekPlan.Rows.Count == 0)
            {
                this.gdvWeekPlan.DataSource = createDataTable();
                this.gdvWeekPlan.DataBind();
            }

            #region
            for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
            {

                if (this.gdvWeekPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)this.gdvWeekPlan.Rows[i].Cells[12].FindControl("btnDownLoad2");
                    _btn.Visible = false;
                    Label _lbl = (Label)this.gdvWeekPlan.Rows[i].Cells[12].FindControl("lblAlert2");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }
            #endregion

            #endregion
            processGridViewForWeek(_gridView);
        }
        if (_gridView.Equals(this.gdvPreWeekPlanNoCompelete))
        {
            #region 绑定上周未完成计划
            this.gdvPreWeekPlanNoCompelete.DataSource = new DataTable();
            this.gdvPreWeekPlanNoCompelete.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = this.dllUserPlanWeek.getPreWeekPlanNoComplete(_value);
            if (_weekPlan.Tables.Count > 0)
            {
                for (int j = 0; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvPreWeekPlanNoCompelete.DataSource = dv;
                        this.gdvPreWeekPlanNoCompelete.DataBind();
                    }
                }
            }

            if (this.gdvPreWeekPlanNoCompelete.Rows.Count == 0)
            {
                this.gdvPreWeekPlanNoCompelete.DataSource = createDataTable();
                this.gdvPreWeekPlanNoCompelete.DataBind();
            }

            #region
            for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
            {

                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[12].FindControl("btnDownLoad3");
                    _btn.Visible = false;
                    Label _lbl = (Label)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[12].FindControl("lblAlert3");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }
            #endregion

            #endregion
            processGridView(_gridView);
        }
        if (_gridView.Equals(this.gdvWeekPlanContinue))
        {
            #region 绑定上周持续计划
            this.gdvWeekPlanContinue.DataSource = new DataTable();
            this.gdvWeekPlanContinue.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
            _value[1] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _weekPlan = dllUserPlanWeek.getUserWeekPlanContinue(_value);
            if (_weekPlan.Tables.Count > 0)
            {
                for (int j = 0; j < _weekPlan.Tables.Count; j++)
                {
                    if (_weekPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_weekPlan.Tables[j]);
                        dv.Sort = "WeekPlanSortId";
                        this.gdvWeekPlanContinue.DataSource = dv;
                        this.gdvWeekPlanContinue.DataBind();
                    }
                }
            }
            if (this.gdvWeekPlanContinue.Rows.Count == 0)
            {
                this.gdvWeekPlanContinue.DataSource = createDataTable();
                this.gdvWeekPlanContinue.DataBind();
            }
            for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
            {

                if (this.gdvWeekPlanContinue.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)this.gdvWeekPlanContinue.Rows[i].Cells[12].FindControl("btnDownLoad4");
                    _btn.Visible = false;
                    Label _lbl = (Label)this.gdvWeekPlanContinue.Rows[i].Cells[12].FindControl("lblAlert4");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }
            #endregion
            processGridViewForWeek(_gridView);
        }

    }

    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridView(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            wrapByComma(_gridView, i, 5);
            if (_gridView.Rows[i].Cells[8].Text != "&nbsp;" && _gridView.Rows[i].Cells[8].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //计划调整变灰
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                {
                    _gridView.Rows[i].Cells[8].Text = "达成共识";
                }
                else
                {
                    _gridView.Rows[i].Cells[8].Text = "";
                }
            }
            if (_gridView.Rows[i].Cells[10].Text == "&nbsp;" || _gridView.Rows[i].Cells[10].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[10].Text = "";
            }
            if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
        }
    }

    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewPre(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[2].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            wrapByComma(_gridView, i, 7);

            if (_gridView.DataKeys[i]["PlanSendState"] != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //计划调整变灰
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[11].Text = "达成共识<br>" + _gridView.Rows[i].Cells[11].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[11].Text = "";
                //}
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;" || _gridView.Rows[i].Cells[8].Text.Contains("&nbsp;"))
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}

            #region 2010-06-03合并审核意见和达成共识
            //if (_gridView.Rows[i].Cells[10].Text != "&nbsp;" && _gridView.Rows[i].Cells[10].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
            //    }

            //    //判断2次以上变红为失控状态
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    //失控标红
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "";
            //    }
            //}
            //if (_gridView.Rows[i].Cells[12].Text == "&nbsp;" || _gridView.Rows[i].Cells[11].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}
            #endregion
        }
    }

    /// <summary>
    /// 处理日期和来源显示
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewForWeek(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();

            wrapByComma(_gridView, i, 7);

            if (_gridView.DataKeys[i]["PlanSendState"] != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[10].Text = "达成共识<br>" + _gridView.Rows[i].Cells[10].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[10].Text = "";
                //}
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;" || _gridView.Rows[i].Cells[8].Text.Contains("&nbsp;"))
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}

            #region 2010-06-03合并审核意见和达成共识
            //if (_gridView.Rows[i].Cells[11].Text != "&nbsp;" && _gridView.Rows[i].Cells[11].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "";
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //}
            //if (_gridView.Rows[i].Cells[13].Text == "&nbsp;" || _gridView.Rows[i].Cells[13].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[13].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}

            #endregion
        }
    }





    protected void gvlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvWeekPlan.PageIndex = e.NewPageIndex;
        bindGridView(this.gdvWeekPlan);
    }


    /// <summary>
    /// 周计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;
        int _monthPlanId = Convert.ToInt32(_gdv.DataKeys[i]["MonthPlanId"].ToString());
        int DepartWeekId = Convert.ToInt32(_gdv.DataKeys[i]["DepartWeekPlanId"].ToString());
        if (_monthPlanId == 0 && DepartWeekId == 0)
        {
            //新增的不链接页面
        }
        else if (_monthPlanId > 0)
        {
            string _url = "UserWeekPlanSource.aspx?MonthPlanId=" + _monthPlanId + "&TypeId=0";
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=160,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
        else
        {
            string _url = "UserWeekPlanSource.aspx?WeekPlanId=" + DepartWeekId + "&TypeId=1";
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=160,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }





    /// <summary>
    /// dropDownList项改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-3-11</date>
    protected void drpDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem != null && this.drpDepartment.SelectedItem.Text != "请选择部门")
        {
            bindDropDownList(this.drpUserInfo);
        }
        this.btnAddWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = true;
        this.btnSaveWeekSummary.Visible = false;
        this.btnSavePreWeekSummary.Visible = false;
    }


    /// <summary>
    /// 投影显示事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDisplay_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;

        string _url = "WeekPlanDisplay.aspx?Id=" + Convert.ToInt32(this.drpWeekDate.SelectedValue) + "&depart=" + department;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=715,width=1015,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
    }

    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvPreWeekPlan.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }
    protected void btnDownLoad2_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvWeekPlan.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }
    protected void btnDownLoad3_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvPreWeekPlanNoCompelete.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }
    protected void btnDownLoad4_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvWeekPlanContinue.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }




    /// <summary>
    /// 年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
        bindDropDownList(this.drpWeekDate);
    }


    /// <summary>
    /// 月周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpWeekDate);
    }


    /// <summary>
    /// 周周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpWeekDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView(this.gdvWeekPlan);
        bindGridView(this.gdvPreWeekPlan);
        bindGridView(this.gdvPreWeekPlanNoCompelete);
        bindGridView(this.gdvWeekPlanContinue);
        this.btnAddWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = true;
        this.btnSaveWeekSummary.Visible = false;
        this.btnSavePreWeekSummary.Visible = false;
    }

    /// <summary>
    /// 年份改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
    }

    /// <summary>
    /// 下载Excel文件方法(弹出对话框)
    /// </summary>
    /// <param name="filename">路径</param>
    /// <param name="strname">文件名</param>
    protected void DownloadFile(string filename, string strname)
    {
        string saveFileName = "";
        int intStart = filename.LastIndexOf('\\') + 1;
        saveFileName = filename.Substring(intStart, filename.Length - intStart);
        FileStream MyFileStream;
        long FileSize;

        String path = Request.PhysicalApplicationPath;
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += "\\Excel\\Week\\";
        path += strname;
        MyFileStream = new FileStream(path, FileMode.Open);
        FileSize = MyFileStream.Length;

        byte[] Buffer = new byte[(int)FileSize];
        MyFileStream.Read(Buffer, 0, (int)FileSize);
        MyFileStream.Close();

        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName));
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "application/vnd.ms-excel";

        Response.BinaryWrite(Buffer);
        Response.Flush();
        Response.Close();
        Response.End();
    }

    /// <summary>
    /// 写入excel
    /// </summary>
    /// <param name="strFilePathName"></param>
    /// <param name="objDataGrid"></param>
    /// <param name="strHeader"></param>
    /// <param name="strFooter"></param>
    /// <returns></returns>
    public static bool ExportToExcel(string strFilePathName, GridView objDataGrid, string strHeader, string strFooter)
    {
        //返回值
        bool bReturn = false;

        //判断datagrid是否为空
        if (null == objDataGrid)
        {
            return bReturn;
        }
        //表格的样式
        COM.Excel.cExcelFile objExcel = new COM.Excel.cExcelFile();
        int a = objExcel.CreateFile(strFilePathName);

        objExcel.PrintGridLines = false;
        COM.Excel.cExcelFile.MarginTypes mt1 = COM.Excel.cExcelFile.MarginTypes.xlsTopMargin;
        COM.Excel.cExcelFile.MarginTypes mt2 = COM.Excel.cExcelFile.MarginTypes.xlsLeftMargin;
        COM.Excel.cExcelFile.MarginTypes mt3 = COM.Excel.cExcelFile.MarginTypes.xlsRightMargin;
        COM.Excel.cExcelFile.MarginTypes mt4 = COM.Excel.cExcelFile.MarginTypes.xlsBottomMargin;
        double height = 1.5;
        objExcel.SetMargin(ref mt1, ref height);
        objExcel.SetMargin(ref mt2, ref height);
        objExcel.SetMargin(ref mt3, ref height);
        objExcel.SetMargin(ref mt4, ref height);
        COM.Excel.cExcelFile.FontFormatting ff = COM.Excel.cExcelFile.FontFormatting.xlsNoFormat;
        string font = "Arial";
        short fontsize = 12;
        objExcel.SetFont(ref font, ref fontsize, ref ff);



        byte b1 = 1, b2 = 12;
        short s3 = 18;
        objExcel.SetColumnWidth(ref b1, ref b2, ref s3);

        string header = strHeader;
        string footer = strFooter;
        objExcel.SetHeader(ref header);
        objExcel.SetFooter(ref footer);

        COM.Excel.cExcelFile.ValueTypes vt = COM.Excel.cExcelFile.ValueTypes.xlsText;
        COM.Excel.cExcelFile.CellFont cf = COM.Excel.cExcelFile.CellFont.xlsFont0;
        COM.Excel.cExcelFile.CellAlignment ca = COM.Excel.cExcelFile.CellAlignment.xlsLeftAlign;
        COM.Excel.cExcelFile.CellHiddenLocked chl = COM.Excel.cExcelFile.CellHiddenLocked.xlsNormal;
        //定义表格的起始点 

        int iFormat = 0;
        int iOutRow = 0;
        int iOutCol = 0;
        int iRowCount = 0;
        //获得该datagrid的列的数量
        int iColCount = objDataGrid.Columns.Count;


        iRowCount = objDataGrid.Rows.Count;


        //表头

        for (int j = 1; j < iColCount; j++)
        {
            if (objDataGrid.Columns[j].Visible == false)
            {
                continue;
            }
            //显示的信息
            object objValue = objDataGrid.Columns[j].HeaderText;
            iOutRow = 1;
            iOutCol = j + 1;
            objExcel.WriteValue(ref vt, ref cf, ref ca, ref chl, ref iOutRow,
                ref iOutCol, ref objValue, ref iFormat);
        }
        //内容
        for (int i = 1; i <= iRowCount; i++)
        {
            for (int j = 0; j < iColCount; j++)
            {
                if (objDataGrid.Columns[j].Visible == false)
                {
                    continue;
                }
                //显示的信息
                object objValue = objDataGrid.Rows[i - 1].Cells[j].Text;
                iOutRow = i + 1;
                iOutCol = j + 1;
                objExcel.WriteValue(ref vt, ref cf, ref ca, ref chl, ref iOutRow,
                    ref iOutCol, ref objValue, ref iFormat);
            }
        }
        bReturn = true;
        objExcel.CloseFile();
        return bReturn;
    }


    /// <summary>
    /// 导出上周计划excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelPreWeek_Click(object sender, EventArgs e)
    {
        if (this.gdvPreWeekPlan.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周计划";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvPreWeekPlan, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("上周计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出本周
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelWeek_Click(object sender, EventArgs e)
    {
        if (this.gdvWeekPlan.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-本周计划";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvWeekPlan, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("本周计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出上周未完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelPreWeekNoCom_Click(object sender, EventArgs e)
    {
        if (this.gdvPreWeekPlanNoCompelete.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周未完成";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvPreWeekPlanNoCompelete, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("上周未完成计划没有数据", Page);
        }
    }


    /// <summary>
    /// 导出持续周
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcelWeekContinue_Click(object sender, EventArgs e)
    {
        if (this.gdvWeekPlanContinue.Rows.Count > 1)
        {
            string str = this.drpWeekDate.SelectedItem.Text + "-上周未完成";
            string strname = str + ".xls";

            String path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            //删除过期
            string[] filename = Directory.GetFiles(path);
            for (int i = 0; i < filename.Length; i++)
            {
                path = filename[i];
                FileInfo fi = new FileInfo(path);
                if (DateTime.Now.ToShortDateString() == fi.CreationTime.ToShortDateString())
                {
                    System.IO.File.Delete(path);
                }
            }
            path = Request.PhysicalApplicationPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path += "\\Excel\\Week\\";
            path += strname;
            ExportToExcel(path, this.gdvWeekPlanContinue, "aa", "bb");
            DownloadFile(path, strname);
        }
        else
        {
            Utility.HttpHelp.alert("持续计划没有数据", Page);
        }
    }


    /// <summary>
    /// 员工改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpUserInfo_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpUserInfo.SelectedItem != null)
        {
            bindGridView(this.gdvWeekPlan);
            bindGridView(this.gdvPreWeekPlan);
            bindGridView(this.gdvPreWeekPlanNoCompelete);
            bindGridView(this.gdvWeekPlanContinue);
        }
    }


    /// <summary>
    /// 修改本周员工周计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyMonth_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _weekId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                _count++;
            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        if (_count == 1)
        {
            //判断计划是否二次评估完成
            object[] _value = new object[1];
            _value[0] = _weekId;
            BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
            DataTable weekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (weekplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(weekplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _weekId;
                DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), UserPlanWeek.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpWeekDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "UserWeekPlanModify.aspx?Id=" + _weekId + "&url=UserPlanWeekList.aspx&Year=" + this.drpYear.SelectedValue + "&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&MonthDate=" + this.drpMonthDate.SelectedValue + "&WeekDate=" + _li.Value + "&depart=" + department + "&User=" + this.drpUserInfo.SelectedValue;
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
    }


    /// <summary>
    /// 修改上周未完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyPre_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _weekId = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString());
                _count++;
            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        if (_count == 1)
        {
            //判断计划是否二次评估完成
            object[] _value = new object[1];
            _value[0] = _weekId;
            BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
            DataTable weekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (weekplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(weekplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _weekId;
                DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), UserPlanWeek.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpWeekDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "UserWeekPlanModify.aspx?Id=" + _weekId + "&url=UserPlanWeekList.aspx&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&WeekDate=" + _li.Value + "&depart=" + department + "&User=" + this.drpUserInfo.SelectedValue;
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
    }



    /// <summary>
    /// 修改可持续员工周计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyContinue_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _weekId = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                _count++;
            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        if (_count == 1)
        {
            //判断计划是否二次评估完成
            object[] _value = new object[1];
            _value[0] = _weekId;
            BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
            DataTable weekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (weekplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(weekplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _weekId;
                DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), UserPlanWeek.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpWeekDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "UserWeekPlanModify.aspx?Id=" + _weekId + "&url=UserPlanWeekList.aspx&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue + "&WeekDate=" + _li.Value + "&depart=" + department + "&User=" + this.drpUserInfo.SelectedValue;
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
    }
    protected void btnFlow_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _weekId = 0;
        //上周
        for (int i = 0; i < this.gdvPreWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvPreWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //本周
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //上周未完成
        for (int i = 0; i < this.gdvPreWeekPlanNoCompelete.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreWeekPlanNoCompelete.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"] != null && this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvPreWeekPlanNoCompelete.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        //持续计划
        for (int i = 0; i < this.gdvWeekPlanContinue.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlanContinue.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"] != null && this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString().Length != 0)
                {

                    _weekId = Convert.ToInt32(this.gdvWeekPlanContinue.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {
            string _url = "../WebCommon/VerifyCircruitForUserPlanDisplay.aspx?PlanId=" + _weekId + "&PlanType=5";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");


        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个周计划", Page);
            return;
        }
    }


    /// <summary>
    /// 导出excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnToExcel_Click(object sender, EventArgs e)
    {
        GridView[] _gridView = new GridView[4];
        _gridView[0] = this.gdvPreWeekPlan;
        _gridView[1] = this.gdvWeekPlan;
        _gridView[2] = this.gdvPreWeekPlanNoCompelete;
        _gridView[3] = this.gdvWeekPlanContinue;
        Utility.Comm.UserWeekToExcel(GridViewToDataTable(_gridView), this.drpDepartment.SelectedItem.Text, this.drpUserInfo.SelectedItem.Text, this.drpYear.SelectedItem.Text + "年" + this.drpWeekDate.SelectedItem.Text);
    }

    /// <summary>
    /// GridView转DataTable
    /// </summary>
    DataTable[] GridViewToDataTable(GridView[] _sourceGridView)
    {
        DataTable[] _targetDataTable = new DataTable[_sourceGridView.Length];
        for (int i = 0; i < _targetDataTable.Length; i++)
        {
            _targetDataTable[i] = new DataTable();
            DataColumn dc = new DataColumn();
            //根据源GridView循环创建目标DataTable列
            for (int j = 0; j < _sourceGridView[i].Columns.Count; j++)
            {
                if (_sourceGridView[i].Columns[j].Visible == true)
                {
                    dc = new DataColumn(_sourceGridView[i].Columns[j].HeaderText);
                    _targetDataTable[i].Columns.Add(dc);
                }
            }
            //根据源GridView循环创建目标DataTable行
            for (int j = 0; j < _sourceGridView[i].Rows.Count; j++)
            {
                DataRow dr = _targetDataTable[i].NewRow();
                for (int k = 0; k < _sourceGridView[i].Columns.Count; k++)
                {

                    if (_sourceGridView[i].Columns[k].Visible == true && k < _targetDataTable[i].Columns.Count)
                    {
                        if (_sourceGridView[i].Columns[k].HeaderText == "计划来源")
                        {
                            LinkButton lbtn = (LinkButton)_sourceGridView[i].Rows[j].Cells[k].FindControl("lbtnSource");
                            dr[k] = lbtn.Text;
                        }
                        else
                        {
                            dr[k] = _sourceGridView[i].Rows[j].Cells[k].Text;
                        }

                    }

                }
                _targetDataTable[i].Rows.Add(dr);
            }

        }
        return _targetDataTable;
    }


    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        List<object[]> _valueList = new List<object[]>();
        int _count = 0;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                object[] _value = new object[1];
                _value[0] = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                _valueList.Add(_value);
            }
        }
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("选择要删除的计划", Page);
            return;
        }
        if (_valueList.Count > 0)
        {
            BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
            int _result = dllUserPlanWeek.delWithTransaction(UserPlanWeek.field.WeekPlanId.ToString(), _valueList);
            if (_result == 0)
            {
                Utility.HttpHelp.redirectPage("删除计划未成功，请重试");
            }
            else
            {
                bindGridView(this.gdvWeekPlan);
            }
        }
    }


    protected void btnAddPreWeekSummary_Click(object sender, EventArgs e)
    {
        this.btnSavePreWeekSummary.Visible = true;
        this.btnAddPreWeekSummary.Visible = false;
        this.txtPreWeekSummary.ReadOnly = false;
        if (this.txtPreWeekSummary.Text == "注：工作总结不少于3条，总字数不少于60个字。")
        {
            this.txtPreWeekSummary.Text = "";
        }
        //this.lblPreWeekSummary.Visible = false;
    }
    protected void btnAddWeekSummary_Click(object sender, EventArgs e)
    {
        this.btnSaveWeekSummary.Visible = true;
        this.btnAddWeekSummary.Visible = false;
        this.txtWeekSummary.ReadOnly = false;
        if (this.txtWeekSummary.Text == "注：工作部署不少于3条，总字数不少于60个字。")
        {
            this.txtWeekSummary.Text = "";
        }
        //this.lblWeekSummary.Visible = false;
    }

    protected void btnSavePreWeekSummary_Click(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem.Text != "请选择部门")
        {
            if (sender.Equals(this.btnSavePreWeekSummary))
            {
                if (this.txtPreWeekSummary.Text.Length < 60)
                {
                    Utility.HttpHelp.alert("字数不得少于60字！", this.Page);
                    return;
                }
            }
            else
            {
                if (this.txtWeekSummary.Text.Length < 60)
                {
                    Utility.HttpHelp.alert("字数不得少于60字！", this.Page);
                    return;
                }
            }
            if (this.HWeekSummaryId.Value.Length > 0)
            {
                
                //修改
                object[] _value = new object[7];
                _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
                _value[1] = this.txtPreWeekSummary.Text;
                _value[2] = this.txtWeekSummary.Text;
                _value[3] = objUserInfo.UserName;
                BLL.UserInfoManager dllUserInfo = new BLL.UserInfoManager();
                DataTable dt = dllUserInfo.get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
                _value[4] = Convert.ToInt32(dt.Rows[0]["UserId"]);
                _value[5] = this.drpDepartment.SelectedItem.Text;
                _value[6] = Convert.ToInt32(this.HWeekSummaryId.Value);
                int val = new BLL.UserWeekSummary().editWeekSummary(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreWeekPlan);
                }
                else
                {
                    Utility.HttpHelp.alert("修改失败", this.Page);
                }
            }
            else
            {
                //添加
                object[] _value = new object[6];
                _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
                _value[1] = this.txtPreWeekSummary.Text;
                _value[2] = this.txtWeekSummary.Text;
                _value[3] = objUserInfo.UserName;
                _value[4] = this.drpDepartment.SelectedItem.Text;
                _value[5] = Convert.ToInt32(this.drpUserInfo.SelectedValue);
                int val = new BLL.UserWeekSummary().add(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreWeekPlan);
                }
                else
                {
                    Utility.HttpHelp.alert("添加失败", this.Page);
                }
            }
            if (sender.Equals(this.btnSaveWeekSummary))
            {
                this.btnAddWeekSummary.Visible = true;
                this.btnSaveWeekSummary.Visible = false;
                this.txtWeekSummary.ReadOnly = false;
                //this.lblWeekSummary.Visible = true;
            }
            if (sender.Equals(this.btnSavePreWeekSummary))
            {
                this.btnAddPreWeekSummary.Visible = true;
                this.btnSavePreWeekSummary.Visible = false;
                this.txtPreWeekSummary.ReadOnly = false;
                //this.lblPreWeekSummary.Visible = true;
            }
        }
        else
        {
            Utility.HttpHelp.alert("请选择部门", this.Page);
        }
    }


    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (this.HWeekSummaryId.Value.Length > 0)
        {
            if (sender.Equals(this.btnUploadWeekSummary))
            {
                //定向到添加本月附件路径页面
                string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HWeekSummaryId.Value + "&PlanType=23&Url=UserPlanWeekList.aspx";
                Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            }
            else
            {
                //定向到添加上月附件路径页面
                string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HWeekSummaryId.Value + "&PlanType=24&Url=UserPlanWeekList.aspx";
                Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            }
        }
        else
        {
            if (sender.Equals(this.btnUploadWeekSummary))
            {
                Utility.HttpHelp.alert("请先添加本周总结", this.Page);
            }
            else
            {
                Utility.HttpHelp.alert("请先添加上周总结", this.Page);
            }

        }
    }
    protected void btnDownWeekSummary_Click(object sender, EventArgs e)
    {
        if (sender.Equals(this.btnDownWeekSummary))
        {
            string path = this.HAttachmentPath.Value;
            FileDownload(path);
        }
        else
        {
            string path = this.HPreAttachmentPath.Value;
            FileDownload(path);
        }
    }
}
